﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Evaluation3.data;
using System.Data.OleDb;
using Evaluation3.classes;
using System.Web.Configuration;

public partial class uicontrol_Nhap_Diem_Hieu_Qua : System.Web.UI.UserControl
{
  OleDbConnection myConnection;
  remoteUser objRemoteUser;
  String MaSanPham = "";
  String MaHoiDong = "";
  DataRow dr;
  int identity = 0;
  //-----------------------
  HieuQuaCongNghe_ThongTin objHieuQuaCongNghe_ThongTin_Temp;
  HieuQuaCongNghe_ThongTin objHQCNTT;
  //----------------------
  HieuQuaCongNghe_KyThuat objHieuQuaCongNghe_KyThuat_Temp;
  HieuQuaCongNghe_KyThuat objHQCNKT;
  //----------------------
  HieuQuaCongNghe_ToChuc objHieuQuaCongNghe_ToChuc_Temp;
  HieuQuaCongNghe_ToChuc objHQCNTC;
  //----------------------
  NhanToConNguoi objNhanToConNguoi_Temp;
  NhanToConNguoi objNTCN;
  //----------------------

    protected void Page_Load(object sender, EventArgs e)
    {
      String connectinString = WebConfigurationManager.ConnectionStrings["Evaluation"].ConnectionString;
      myConnection = new OleDbConnection(connectinString);
      objRemoteUser = (remoteUser)Session["remoteUser"];
      MaSanPham = (String)Session["MaSanPham"];
      MaHoiDong = (String)Session["MaHoiDong"];

      //--------------------------------
      if (!IsPostBack)
      {
        LoadDataToGrid_HQCNTT();
        LoadDataToGrid_HQCNKT();
        LoadDataToGrid_HQCNTC();
        LoadDataToGrid_NTCN();
      }
    }

  private void LoadDataToGrid_HQCNTT()
  {
    objHieuQuaCongNghe_ThongTin_Temp = new HieuQuaCongNghe_ThongTin();
    objHieuQuaCongNghe_ThongTin_Temp.ActiveConnection = myConnection;
    objHieuQuaCongNghe_ThongTin_Temp.SelectCondition = "MaSanPham='" + MaSanPham + "' and MaHoiDong='" + MaHoiDong + "'";
    objHieuQuaCongNghe_ThongTin_Temp.LoadData();
    if (Session["objHieuQuaCongNghe_ThongTin_Temp"] != null)
    {
      Session["objHieuQuaCongNghe_ThongTin_Temp"] = null;
    }
    Session["objHieuQuaCongNghe_ThongTin_Temp"] = objHieuQuaCongNghe_ThongTin_Temp;
    GridView_HieuQuaCongNghe_ThongTin.DataSource = (HieuQuaCongNghe_ThongTin)Session["objHieuQuaCongNghe_ThongTin_Temp"];
    GridView_HieuQuaCongNghe_ThongTin.DataBind();
  }

  private void LoadDataToGrid_HQCNKT()
  {
    objHieuQuaCongNghe_KyThuat_Temp = new HieuQuaCongNghe_KyThuat();
    objHieuQuaCongNghe_KyThuat_Temp.ActiveConnection = myConnection;
    objHieuQuaCongNghe_KyThuat_Temp.SelectCondition = "MaSanPham='" + MaSanPham + "' and MaHoiDong='" + MaHoiDong + "'";
    objHieuQuaCongNghe_KyThuat_Temp.LoadData();
    if (Session["objHieuQuaCongNghe_KyThuat_Temp"] != null)
    {
      Session["objHieuQuaCongNghe_KyThuat_Temp"] = null;
    }
    Session["objHieuQuaCongNghe_KyThuat_Temp"] = objHieuQuaCongNghe_KyThuat_Temp;
    GridView_HieuQuaCongNghe_KyThuat.DataSource = (HieuQuaCongNghe_KyThuat)Session["objHieuQuaCongNghe_KyThuat_Temp"];
    GridView_HieuQuaCongNghe_KyThuat.DataBind();
  }

  private void LoadDataToGrid_HQCNTC()
  {
    objHieuQuaCongNghe_ToChuc_Temp = new HieuQuaCongNghe_ToChuc();
    objHieuQuaCongNghe_ToChuc_Temp.ActiveConnection = myConnection;
    objHieuQuaCongNghe_ToChuc_Temp.SelectCondition = "MaSanPham='" + MaSanPham + "' and MaHoiDong='" + MaHoiDong + "'";
    objHieuQuaCongNghe_ToChuc_Temp.LoadData();
    if (Session["objHieuQuaCongNghe_ToChuc_Temp"] != null)
    {
      Session["objHieuQuaCongNghe_ToChuc_Temp"] = null;
    }
    Session["objHieuQuaCongNghe_ToChuc_Temp"] = objHieuQuaCongNghe_ToChuc_Temp;
    GridView_HieuQuaCongNghe_ToChuc.DataSource = (HieuQuaCongNghe_ToChuc)Session["objHieuQuaCongNghe_ToChuc_Temp"];
    GridView_HieuQuaCongNghe_ToChuc.DataBind();
  }

  private void LoadDataToGrid_NTCN()
  {
    objNhanToConNguoi_Temp = new NhanToConNguoi();
    objNhanToConNguoi_Temp.ActiveConnection = myConnection;
    objNhanToConNguoi_Temp.SelectCondition = "MaSanPham='" + MaSanPham + "' and MaHoiDong='" + MaHoiDong + "'";
    objNhanToConNguoi_Temp.LoadData();
    if (Session["objNhanToConNguoi_Temp"] != null)
    {
      Session["objNhanToConNguoi_Temp"] = null;
    }
    Session["objNhanToConNguoi_Temp"] = objNhanToConNguoi_Temp;
    GridView_NhanToConNguoi.DataSource = (NhanToConNguoi)Session["objNhanToConNguoi_Temp"];
    GridView_NhanToConNguoi.DataBind();
  }





  protected void bntAddNew_TT_Click(object sender, EventArgs e)
  {
    identity -= 1;
    txtMaHieuQuaCongNghe_ThongTin.Text = identity.ToString();
    txtTenHieuQuaCongNghe_ThongTin.Text = "";
    txtGhiChu_TT.Text = "";
    txtTenHieuQuaCongNghe_ThongTin.Enabled = true;
    txtGhiChu_TT.Enabled = true;
  }

  protected void bntSave_TT_Click(object sender, EventArgs e)
  {
    try
    {
      if (txtTenHieuQuaCongNghe_ThongTin.Text == null || txtTenHieuQuaCongNghe_ThongTin.Text.Trim().Length < 1)
      {
        lblTenHieuQuaCongNghe_ThongTin.Text = "* Tên hiệu quả công nghệ thông tin không được để trống!";
        lblTenHieuQuaCongNghe_ThongTin.Visible = true;
        txtTenHieuQuaCongNghe_ThongTin.Focus();
        return;
      }
      else
      {
        lblTenHieuQuaCongNghe_ThongTin.Visible = false;
      }

      if (txtMaHieuQuaCongNghe_ThongTin.Text.ToString().Trim().Length > 0 && Convert.ToInt32(txtMaHieuQuaCongNghe_ThongTin.Text) > 0)
      {

        objHQCNTT = (HieuQuaCongNghe_ThongTin)Session["objHieuQuaCongNghe_ThongTin_Temp"];
        dr = objHQCNTT.FindByPrimaryKey(txtMaHieuQuaCongNghe_ThongTin.Text.ToString());
        dr["TenHieuQuaCongNghe_ThongTin"] = txtTenHieuQuaCongNghe_ThongTin.Text;
        dr["GhiChu"] = txtGhiChu_TT.Text;
        objHQCNTT.SaveData(Evaluation3.data.MyDataTable.DataTableAction.AllChanges);
      }
      if (txtMaHieuQuaCongNghe_ThongTin.Text.ToString().Trim().Length > 0 && Convert.ToInt32(txtMaHieuQuaCongNghe_ThongTin.Text) < 0)
      {
        identity -= 1;
        objHQCNTT = (HieuQuaCongNghe_ThongTin)Session["objHieuQuaCongNghe_ThongTin_Temp"];
        dr = objHQCNTT.NewRow();
        dr["MaHieuQuaCongNghe_ThongTin"] = identity;
        dr["TenHieuQuaCongNghe_ThongTin"] = txtTenHieuQuaCongNghe_ThongTin.Text;
        dr["MaSanPham"] = MaSanPham;
        dr["MaHoiDong"] = MaHoiDong;
        dr["GhiChu"] = txtGhiChu_TT.Text;
        objHQCNTT.Rows.Add(dr);
        objHQCNTT.SaveData(Evaluation3.data.MyDataTable.DataTableAction.AllChanges);
      }

      LoadDataToGrid_HQCNTT();
      txtMaHieuQuaCongNghe_ThongTin.Text = "";
      txtTenHieuQuaCongNghe_ThongTin.Text = "";
      txtGhiChu_TT.Text = "";
      txtTenHieuQuaCongNghe_ThongTin.Enabled = false;
      txtGhiChu_TT.Enabled = false;
    }
    catch (Exception eRow9)
    {

    }
  }
  protected void bntDelete_TT_Click(object sender, EventArgs e)
  {
    if (txtMaHieuQuaCongNghe_ThongTin.Text.ToString().Trim().Length > 0 && Convert.ToInt32(txtMaHieuQuaCongNghe_ThongTin.Text) > 0)
    {

      objHQCNTT = (HieuQuaCongNghe_ThongTin)Session["objHieuQuaCongNghe_ThongTin_Temp"];
      dr = objHQCNTT.FindByPrimaryKey(txtMaHieuQuaCongNghe_ThongTin.Text.ToString());
      dr.Delete();
      objHQCNTT.SaveData(Evaluation3.data.MyDataTable.DataTableAction.Delete);
      LoadDataToGrid_HQCNTT();
      txtMaHieuQuaCongNghe_ThongTin.Text = "";
      txtTenHieuQuaCongNghe_ThongTin.Text = "";
      txtGhiChu_TT.Text = "";
      txtTenHieuQuaCongNghe_ThongTin.Enabled = false;      
      txtGhiChu_TT.Enabled = false;
    }
  }
  protected void GridView_HieuQuaCongNghe_ThongTin_PageIndexChanging(object sender, GridViewPageEventArgs e)
  {
    GridView_HieuQuaCongNghe_ThongTin.PageIndex = e.NewPageIndex;
    LoadDataToGrid_HQCNTT();
  }
  protected void GridView_HieuQuaCongNghe_ThongTin_RowCommand(object sender, GridViewCommandEventArgs e)
  {

    try
    {
      int selectedrow = Convert.ToInt32(e.CommandArgument);
      objHQCNTT = (HieuQuaCongNghe_ThongTin)Session["objHieuQuaCongNghe_ThongTin_Temp"];
      dr = objHQCNTT.FindByPrimaryKey(GridView_HieuQuaCongNghe_ThongTin.Rows[selectedrow].Cells[0].Text.ToString());
      txtMaHieuQuaCongNghe_ThongTin.Text = dr["MaHieuQuaCongNghe_ThongTin"].ToString();
      txtTenHieuQuaCongNghe_ThongTin.Text = dr["TenHieuQuaCongNghe_ThongTin"].ToString();
      txtGhiChu_TT.Text = dr["GhiChu"].ToString();
      txtTenHieuQuaCongNghe_ThongTin.Enabled = true;
      txtGhiChu_TT.Enabled = true;
    }
    catch (Exception eRow1)
    { 
      
    }
  }
  protected void GridView_HieuQuaCongNghe_ThongTin_RowDataBound(object sender, GridViewRowEventArgs e)
  {
    if ((e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate) && (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header))
    {
      //Giấu đi cột Mã Sản phẩm            
      e.Row.Cells[0].Visible = false;
      e.Row.Cells[2].Visible = false;
      e.Row.Cells[3].Visible = false;
    }
  }
  protected void bntAddNew_KT_Click(object sender, EventArgs e)
  {
    identity -= 1;
    txtMaHieuQuaCongNghe_KyThuat.Text = identity.ToString();
    txtTenHieuQuaCongNghe_KyThuat.Text = "";
    txtGhiChu_KT.Text = "";
    txtTenHieuQuaCongNghe_KyThuat.Enabled = true;
    txtGhiChu_KT.Enabled = true;
  }
  protected void bntSave_KT_Click(object sender, EventArgs e)
  {
    try
    {
      if (txtTenHieuQuaCongNghe_KyThuat.Text == null || txtTenHieuQuaCongNghe_KyThuat.Text.Trim().Length < 1)
      {
        lblTenHieuQuaCongNghe_KyThuat.Text = "* Tên hiệu quả công nghệ kỹ thuật không được để trống!";
        lblTenHieuQuaCongNghe_KyThuat.Visible = true;
        txtTenHieuQuaCongNghe_KyThuat.Focus();
        return;
      }
      else
      {
        lblTenHieuQuaCongNghe_KyThuat.Visible = false;
      }

      if (txtMaHieuQuaCongNghe_KyThuat.Text.ToString().Trim().Length > 0 && Convert.ToInt32(txtMaHieuQuaCongNghe_KyThuat.Text) > 0)
      {

        objHQCNKT = (HieuQuaCongNghe_KyThuat)Session["objHieuQuaCongNghe_KyThuat_Temp"];
        dr = objHQCNKT.FindByPrimaryKey(txtMaHieuQuaCongNghe_KyThuat.Text.ToString());
        dr["TenHieuQuaCongNghe_KyThuat"] = txtTenHieuQuaCongNghe_KyThuat.Text;
        dr["GhiChu"] = txtGhiChu_KT.Text;
        objHQCNKT.SaveData(Evaluation3.data.MyDataTable.DataTableAction.AllChanges);
      }
      if (txtMaHieuQuaCongNghe_KyThuat.Text.ToString().Trim().Length > 0 && Convert.ToInt32(txtMaHieuQuaCongNghe_KyThuat.Text) < 0)
      {
        identity -= 1;
        objHQCNKT = (HieuQuaCongNghe_KyThuat)Session["objHieuQuaCongNghe_KyThuat_Temp"];
        dr = objHQCNKT.NewRow();
        dr["MaHieuQuaCongNghe_KyThuat"] = identity;
        dr["TenHieuQuaCongNghe_KyThuat"] = txtTenHieuQuaCongNghe_KyThuat.Text;
        dr["MaSanPham"] = MaSanPham;
        dr["MaHoiDong"] = MaHoiDong;
        dr["GhiChu"] = txtGhiChu_KT.Text;
        objHQCNKT.Rows.Add(dr);
        objHQCNKT.SaveData(Evaluation3.data.MyDataTable.DataTableAction.AllChanges);
      }

      LoadDataToGrid_HQCNKT();
      txtMaHieuQuaCongNghe_KyThuat.Text = "";
      txtTenHieuQuaCongNghe_KyThuat.Text = "";
      txtGhiChu_KT.Text = "";
      txtTenHieuQuaCongNghe_KyThuat.Enabled = false;
      txtGhiChu_KT.Enabled = false;
    }
    catch (Exception eRow3)
    {

    }
  }
  protected void bntDelete_KT_Click(object sender, EventArgs e)
  {
    if (txtMaHieuQuaCongNghe_KyThuat.Text.ToString().Trim().Length > 0 && Convert.ToInt32(txtMaHieuQuaCongNghe_KyThuat.Text) > 0)
    {

      objHQCNKT = (HieuQuaCongNghe_KyThuat)Session["objHieuQuaCongNghe_KyThuat_Temp"];
      dr = objHQCNKT.FindByPrimaryKey(txtMaHieuQuaCongNghe_KyThuat.Text.ToString());
      dr.Delete();
      objHQCNKT.SaveData(Evaluation3.data.MyDataTable.DataTableAction.Delete);
      LoadDataToGrid_HQCNKT();
      txtMaHieuQuaCongNghe_KyThuat.Text = "";
      txtTenHieuQuaCongNghe_KyThuat.Text = "";
      txtGhiChu_KT.Text = "";
      txtTenHieuQuaCongNghe_KyThuat.Enabled = false;
      txtGhiChu_KT.Enabled = false;
    }
  }
  protected void GridView_HieuQuaCongNghe_KyThuat_PageIndexChanging(object sender, GridViewPageEventArgs e)
  {
    GridView_HieuQuaCongNghe_KyThuat.PageIndex = e.NewPageIndex;
    LoadDataToGrid_HQCNKT();
  }
  protected void GridView_HieuQuaCongNghe_KyThuat_RowCommand(object sender, GridViewCommandEventArgs e)
  {
    try
    {
      int selectedrow = Convert.ToInt32(e.CommandArgument);
      objHQCNKT = (HieuQuaCongNghe_KyThuat)Session["objHieuQuaCongNghe_KyThuat_Temp"];
      dr = objHQCNKT.FindByPrimaryKey(GridView_HieuQuaCongNghe_KyThuat.Rows[selectedrow].Cells[0].Text.ToString());
      txtMaHieuQuaCongNghe_KyThuat.Text = dr["MaHieuQuaCongNghe_KyThuat"].ToString();
      txtTenHieuQuaCongNghe_KyThuat.Text = dr["TenHieuQuaCongNghe_KyThuat"].ToString();
      txtGhiChu_KT.Text = dr["GhiChu"].ToString();
      txtTenHieuQuaCongNghe_KyThuat.Enabled = true;
      txtGhiChu_KT.Enabled = true;
    }
    catch (Exception eRow2)
    { 
      
    }

  }
  protected void GridView_HieuQuaCongNghe_KyThuat_RowDataBound(object sender, GridViewRowEventArgs e)
  {
    if ((e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate) && (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header))
    {
      //Giấu đi cột Mã Sản phẩm            
      e.Row.Cells[0].Visible = false;
      e.Row.Cells[2].Visible = false;
      e.Row.Cells[3].Visible = false;
    }
  }
  protected void bntAddNew_TC_Click(object sender, EventArgs e)
  {
    identity -= 1;
    txtMaHieuQuaCongNghe_ToChuc.Text = identity.ToString();
    txtTenHieuQuaCongNghe_ToChuc.Text = "";
    txtGhiChu_TC.Text = "";
    txtTenHieuQuaCongNghe_ToChuc.Enabled = true;
    txtGhiChu_TC.Enabled = true;
  }
  protected void bntSave_TC_Click(object sender, EventArgs e)
  {
    try
    {
      if (txtTenHieuQuaCongNghe_ToChuc.Text == null || txtTenHieuQuaCongNghe_ToChuc.Text.Trim().Length < 1)
      {
        lblTenHieuQuaCongNghe_ToChuc.Text = "* Tên hiệu quả công nghệ tổ chức không được để trống!";
        lblTenHieuQuaCongNghe_ToChuc.Visible = true;
        txtTenHieuQuaCongNghe_ToChuc.Focus();
        return;
      }
      else
      {
        lblTenHieuQuaCongNghe_ToChuc.Visible = false;
      }

      if (txtMaHieuQuaCongNghe_ToChuc.Text.ToString().Trim().Length > 0 && Convert.ToInt32(txtMaHieuQuaCongNghe_ToChuc.Text) > 0)
      {

        objHQCNTC = (HieuQuaCongNghe_ToChuc)Session["objHieuQuaCongNghe_ToChuc_Temp"];
        dr = objHQCNTC.FindByPrimaryKey(txtMaHieuQuaCongNghe_ToChuc.Text.ToString());
        dr["TenHieuQuaCongNghe_ToChuc"] = txtTenHieuQuaCongNghe_ToChuc.Text;
        dr["GhiChu"] = txtGhiChu_TC.Text;
        objHQCNTC.SaveData(Evaluation3.data.MyDataTable.DataTableAction.AllChanges);
      }
      if (txtMaHieuQuaCongNghe_ToChuc.Text.ToString().Trim().Length > 0 && Convert.ToInt32(txtMaHieuQuaCongNghe_ToChuc.Text) < 0)
      {
        identity -= 1;
        objHQCNTC = (HieuQuaCongNghe_ToChuc)Session["objHieuQuaCongNghe_ToChuc_Temp"];
        dr = objHQCNTC.NewRow();
        dr["MaHieuQuaCongNghe_ToChuc"] = identity;
        dr["TenHieuQuaCongNghe_ToChuc"] = txtTenHieuQuaCongNghe_ToChuc.Text;
        dr["MaSanPham"] = MaSanPham;
        dr["MaHoiDong"] = MaHoiDong;
        dr["GhiChu"] = txtGhiChu_TC.Text;
        objHQCNTC.Rows.Add(dr);
        objHQCNTC.SaveData(Evaluation3.data.MyDataTable.DataTableAction.AllChanges);
      }

      LoadDataToGrid_HQCNTC();
      txtMaHieuQuaCongNghe_ToChuc.Text = "";
      txtTenHieuQuaCongNghe_ToChuc.Text = "";
      txtGhiChu_TC.Text = "";
      txtTenHieuQuaCongNghe_ToChuc.Enabled = false;
      txtGhiChu_TC.Enabled = false;
    }
    catch (Exception eRow5)
    {

    }
  }
  protected void bntDelete_TC_Click(object sender, EventArgs e)
  {
    if (txtMaHieuQuaCongNghe_ToChuc.Text.ToString().Trim().Length > 0 && Convert.ToInt32(txtMaHieuQuaCongNghe_ToChuc.Text) > 0)
    {

      objHQCNTC = (HieuQuaCongNghe_ToChuc)Session["objHieuQuaCongNghe_ToChuc_Temp"];
      dr = objHQCNTC.FindByPrimaryKey(txtMaHieuQuaCongNghe_ToChuc.Text.ToString());
      dr.Delete();
      objHQCNTC.SaveData(Evaluation3.data.MyDataTable.DataTableAction.Delete);
      LoadDataToGrid_HQCNTC();
      txtMaHieuQuaCongNghe_ToChuc.Text = "";
      txtTenHieuQuaCongNghe_ToChuc.Text = "";
      txtGhiChu_TC.Text = "";
      txtTenHieuQuaCongNghe_ToChuc.Enabled = false;
      txtGhiChu_TC.Enabled = false;
    }
  }
  protected void GridView_HieuQuaCongNghe_ToChuc_PageIndexChanging(object sender, GridViewPageEventArgs e)
  {
    GridView_HieuQuaCongNghe_ToChuc.PageIndex = e.NewPageIndex;
    LoadDataToGrid_HQCNTC();
  }
  protected void GridView_HieuQuaCongNghe_ToChuc_RowCommand(object sender, GridViewCommandEventArgs e)
  {
    try
    {
      int selectedrow = Convert.ToInt32(e.CommandArgument);
      objHQCNTC = (HieuQuaCongNghe_ToChuc)Session["objHieuQuaCongNghe_ToChuc_Temp"];
      dr = objHQCNTC.FindByPrimaryKey(GridView_HieuQuaCongNghe_ToChuc.Rows[selectedrow].Cells[0].Text.ToString());
      txtMaHieuQuaCongNghe_ToChuc.Text = dr["MaHieuQuaCongNghe_ToChuc"].ToString();
      txtTenHieuQuaCongNghe_ToChuc.Text = dr["TenHieuQuaCongNghe_ToChuc"].ToString();
      txtGhiChu_TC.Text = dr["GhiChu"].ToString();
      txtTenHieuQuaCongNghe_ToChuc.Enabled = true;
      txtGhiChu_TC.Enabled = true;
    }
    catch (Exception eRow4)
    {

    }
  }
  protected void GridView_HieuQuaCongNghe_ToChuc_RowDataBound(object sender, GridViewRowEventArgs e)
  {
    if ((e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate) && (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header))
    {
      //Giấu đi cột Mã Sản phẩm            
      e.Row.Cells[0].Visible = false;
      e.Row.Cells[2].Visible = false;
      e.Row.Cells[3].Visible = false;
    }
  }
  protected void bntAddNew_NTCN_Click(object sender, EventArgs e)
  {
    identity -= 1;
    txtMaNhanToConNguoi.Text = identity.ToString();
    txtTenNhanToConNguoi.Text = "";
    txtAlphaH.Text = "";
    txtTenNhanToConNguoi.Enabled = true;
    txtAlphaH.Enabled = true;
  }
  protected void bntDelete_NTCN_Click(object sender, EventArgs e)
  {
    if (txtMaNhanToConNguoi.Text.ToString().Trim().Length > 0 && Convert.ToInt32(txtMaNhanToConNguoi.Text) > 0)
    {

      objNTCN = (NhanToConNguoi)Session["objNhanToConNguoi_Temp"];
      dr = objNTCN.FindByPrimaryKey(txtMaNhanToConNguoi.Text.ToString());
      dr.Delete();
      objNTCN.SaveData(Evaluation3.data.MyDataTable.DataTableAction.Delete);
      LoadDataToGrid_NTCN();
      txtMaNhanToConNguoi.Text = "";
      txtTenNhanToConNguoi.Text = "";
      txtAlphaH.Text = "";
      txtTenNhanToConNguoi.Enabled = false;
      txtAlphaH.Enabled = false;
    }
  }
  protected void GridView_NhanToConNguoi_PageIndexChanging(object sender, GridViewPageEventArgs e)
  {
    GridView_NhanToConNguoi.PageIndex = e.NewPageIndex;
    LoadDataToGrid_NTCN();
  }
  protected void GridView_NhanToConNguoi_RowCommand(object sender, GridViewCommandEventArgs e)
  {
    try
    {
      int selectedrow = Convert.ToInt32(e.CommandArgument);
      objNTCN = (NhanToConNguoi)Session["objNhanToConNguoi_Temp"];
      dr = objNTCN.FindByPrimaryKey(GridView_NhanToConNguoi.Rows[selectedrow].Cells[0].Text.ToString());
      txtMaNhanToConNguoi.Text = dr["MaNhanToConNguoi"].ToString();
      txtTenNhanToConNguoi.Text = dr["TenNhanToConNguoi"].ToString();
      txtAlphaH.Text = dr["AlphaH"].ToString();
      txtTenNhanToConNguoi.Enabled = true;
      txtAlphaH.Enabled = true;
    }
    catch (Exception eRow6)
    {

    }
  }
  protected void GridView_NhanToConNguoi_RowDataBound(object sender, GridViewRowEventArgs e)
  {
    if ((e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate) && (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header))
    {
      //Giấu đi cột Mã Sản phẩm            
      e.Row.Cells[0].Visible = false;
      e.Row.Cells[2].Visible = false;
      e.Row.Cells[3].Visible = false;
    }
  }
  protected void bntSave_NTCN_Click(object sender, EventArgs e)
  {
    try
    {
      if (txtTenNhanToConNguoi.Text == null || txtTenNhanToConNguoi.Text.Trim().Length < 1)
      {
        lblTenNhanToConNguoi.Text = "* Tên nhân tố con người không được để trống!";
        lblTenNhanToConNguoi.Visible = true;
        txtTenNhanToConNguoi.Focus();
        return;
      }
      else
      {
        lblTenNhanToConNguoi.Visible = false;
      }
      if (txtAlphaH.Text != null)
      {
        try
        {
          double I = 0;
          I = Convert.ToDouble(txtAlphaH.Text);
          if (I < 0 || I > 1)
          {
            lblAlphaH.Text = "* Điểm Alpha H phải trong khoảng từ 0 đến 1!";
            lblAlphaH.Visible = true;
            txtAlphaH.Focus();
            return;
          }
          else
          {
            lblAlphaH.Visible = false;
          }
        }
        catch (Exception eConvert)
        {
          lblAlphaH.Text = "* Điểm Alpha H phải là kiểu số!";
          lblAlphaH.Visible = true;
          txtAlphaH.Focus();
          return;
        }

      }
      else if (txtAlphaH.Text == null)
      {
        lblAlphaH.Text = "* Điểm Alpha H không được để trống!";
        lblAlphaH.Visible = true;
        txtAlphaH.Focus();
        return;
      }
      else
      {
        lblAlphaH.Visible = false;
      }
      if (txtMaNhanToConNguoi.Text.ToString().Trim().Length > 0 && Convert.ToInt32(txtMaNhanToConNguoi.Text) > 0)
      {
        objNTCN = (NhanToConNguoi)Session["objNhanToConNguoi_Temp"];
        dr = objNTCN.FindByPrimaryKey(txtMaNhanToConNguoi.Text.ToString());
        dr["TenNhanToConNguoi"] = txtTenNhanToConNguoi.Text;
        dr["AlphaH"] = txtAlphaH.Text;
        objNTCN.SaveData(Evaluation3.data.MyDataTable.DataTableAction.AllChanges);
      }
      if (txtMaNhanToConNguoi.Text.ToString().Trim().Length > 0 && Convert.ToInt32(txtMaNhanToConNguoi.Text) < 0)
      {
        identity -= 1;
        objNTCN = (NhanToConNguoi)Session["objNhanToConNguoi_Temp"];
        dr = objNTCN.NewRow();
        dr["MaNhanToConNguoi"] = identity;
        dr["TenNhanToConNguoi"] = txtTenNhanToConNguoi.Text;
        dr["AlphaH"] = txtAlphaH.Text;
        dr["MaSanPham"] = MaSanPham;
        dr["MaHoiDong"] = MaHoiDong;
        objNTCN.Rows.Add(dr);
        objNTCN.SaveData(Evaluation3.data.MyDataTable.DataTableAction.AllChanges);
      }

      LoadDataToGrid_NTCN();
      txtMaNhanToConNguoi.Text = "";
      txtTenNhanToConNguoi.Text = "";
      txtAlphaH.Text = "";
      txtTenNhanToConNguoi.Enabled = false;
      txtAlphaH.Enabled = false;
    }
    catch (Exception eRow8)
    {

    }
  }
}
